def pre_sum(a):
    n=len(a)
    sum=[0]*n
    sum[0]=a[0]
    for i in range(1,n):
        sum[i]=sum[i-1]+a[i]
    return sum

def get_sum(sum,l,r):
    if l==0:
        return sum[r]
    return sum[r]-sum[l-1]

s=input()
a=[]
# 处理字符LQ 为 -1 1 前缀和为0的就是平衡串
for i in s:
    if i=='L':
        a.append(-1)
    else:
        a.append(1)
sum=pre_sum(a)
ans=0
for l in range(len(a)):
    for r in range(l,len(a)):
        if get_sum(sum,l,r)==0:
            ans=max(ans,r-l+1)
print(ans)